package com.lzy.rabbitmq;

import com.lzy.pojo.netty.ChatMsg;
import com.lzy.utils.JsonUtils;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *  RabbitMQ的配置类
 */

@Configuration
public class RabbitMQTestConfig {

    // 定义交换机
    public static final String EXCHANGE_NAME = "exchange_test";

    // 定义队列
    public static final String QUEUE_NAME = "queue_test";

    // 具体的路由地址
    public static final String ROUTING_KEY_TEST_SEND = "lzy.wechat.test.send";

    // 具体的路由地址
    public static final String ROUTING_KEY_WECHAT_MSG_SEND = "lzy.wechat.wechat.msg.send";
    // 创建交换机
    @Bean(EXCHANGE_NAME)
    public Exchange exchange(){
        return ExchangeBuilder.topicExchange(EXCHANGE_NAME).durable(true).build();
    }

    // 创建队列
    @Bean(QUEUE_NAME)
    public Queue queue(){
        return QueueBuilder.durable(QUEUE_NAME).build();
    }

    // 定义队列绑定交换机关系
    @Bean
    public Binding binding(@Qualifier(EXCHANGE_NAME) Exchange exchange,
                           @Qualifier(QUEUE_NAME) Queue queue){
        return BindingBuilder
                .bind(queue)
                .to(exchange)
                .with("lzy.wechat.#")
                .noargs(); // 执行绑定关系
    }
}
